<?php

declare(strict_types=1);

namespace App\Utils;

class ImageUtil
{
    public const ossUrl = 'https://ljsh.oss-cn-beijing.aliyuncs.com/';

    /**
     * 对网络地址图片进行提取，返回路径
     */
    public static function cutImageUrl(string $httpurl): string
    {
        preg_match('/https?:\/\/[^\/]*\/(.*)/', $httpurl, $match);

        return $match[1] ?? '';
    }

    /**
     * 组成网络地址
     */
    public static function groupImageUrl(string $imgUri): string
    {
        if ($imgUri) {
            if (substr($imgUri, 0, 4) == 'http') {
                return $imgUri;
            }
            return self::ossUrl . $imgUri;
        } else {
            return '';
        }
    }
}
